import { FacilityType } from "../../../info/GameEnum";
import { AiEnvironment } from "../AiGameAction";
import { DecisionNode } from "../DecisionTree";
import DecisionViewBuild from "./view/DecisionViewBuild";
import DecisionViewDispatch from "./view/DecisionViewDispatch";

export default class DecisionView extends DecisionNode {

    /**
     * invisibilityAttackedMeFac : 攻击过我的 不可见的设施
     * invisibilityFac ：所有不可见的设施
     */
    environment: AiEnvironment;

    constructor(environment: any) {
        super(environment);
        this.childDecisionNodes.push(new DecisionViewBuild(environment));
        this.childDecisionNodes.push(new DecisionViewDispatch(environment));
    }

    /**
     * 对视野的需求
     * 视野对于地图的覆盖率
     * 敌人主基地不在视野内
     * 被不在视野内的炮弹基地攻击
     * @returns 
     */
    evaluate(): number {
        let score = 10;
        //覆盖率
        score += this.environment.player.coveringRate * 20;

        // 敌人主基地不在视野内
        let mainHomeVisibleTime: number = 0;
        this.environment.enemys.forEach(player => {
            this.environment.player.isFacilityVisible(player.facilityArr[FacilityType.主基地][0]) && mainHomeVisibleTime++;
        })
        if (this.environment.enemys.length) {
            score += (this.environment.enemys.length - mainHomeVisibleTime) / this.environment.enemys.length * 20;
        }

        //看不见的，攻击过我的设施
        score += Math.min(2, this.environment.invisibilityAttackedFacility.length) * 25; //1个25 2个及以上50
        return Math.ceil(score);
    }

}